package org.yefei.homeworkday15.six;

public class Rectangle extends Graphics{
	private double a, b;// 长和宽

	public Rectangle(String type, double a, double b) {
		super(type);
		this.a = a;
		this.b = b;
	}

	public double getA() {
		return a;
	}

	public void setA(double a) {
		if (a <= 0) {
			System.err.println("边长不能为非正数！");
			this.a = 6;
		}
		this.a = a;
	}

	public double getB() {
		return b;
	}

	public void setB(double b) {
		if (b <= 0) {
			System.err.println("边长不能为非正数！");
			this.b = 6;
		}
		this.b = b;
	}


	@Override
	public void calPerimeter() {
		if (a > 0 && b > 0) {
		double p = 2 * (a + b);
			System.out.println(super.getType() + "的周长是：" + p);
		} else {
			System.out.println("边长不能为负数和0");
		}
	}

	@Override
	public void calArea() {
		if (a > 0 && b > 0) {
		double area = a * b;
			System.out.println(super.getType() + "的面积是：" + area);
		} else {
			System.out.println("边长不能为负数和0");
		}
	}

}
